/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ggsoft.webapp.action;

import com.ggsoft.timetracker.domain.Timecard;
import com.ggsoft.timetracker.service.TimeTrackerService;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.appfuse.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 *
 * @author giovanella
 * @date Jun 4, 2014
 */
public class TimecardList extends BasePage implements Serializable {
    private TimeTrackerService timeTrackerService;
    private User user;
    private List<User> users;
    private Date loginDate;
    private Boolean currentPeriod = true;
    private String query;
    private List<Timecard> timecards;

    public TimecardList() {
        setSortColumn("id"); 
    }
    
    public void setQuery(String query) {
        this.query = query;
    }

    public String getQuery() {
        return query;
    }            
    
    @Autowired
    public void setTimeTrackerService(@Qualifier("timeTrackerService") TimeTrackerService timeTrackerService) {
        this.timeTrackerService = timeTrackerService;
    }   
    
    public String search() {       
        timecards = timeTrackerService.findTimecards(user, null, loginDate);
        if ((timecards != null && timecards.isEmpty()) || timecards == null) {
            addMessage("records.noResults");
        }
        return "success";
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<User> getUsers() {
        users = userManager.getAll();
        return users;
    }

    public void setUsers(List<User> users) {        
        this.users = users;
    }

    public Date getLoginDate() {
        return loginDate;
    }

    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }        

    public List<Timecard> getTimecards() {
        return timecards;
    }

    public void setTimecards(List<Timecard> timecards) {
        this.timecards = timecards;
    }        

    public Boolean getCurrentPeriod() {
        return currentPeriod;
    }

    public void setCurrentPeriod(Boolean currentPeriod) {
        this.currentPeriod = currentPeriod;
    }        
}
